/**
 * Author: NingpingGou
 * Date: 2012-11-17
 * Description: 
 */
package cn.gnp.framework.core.util;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

/**
 * @author NingpingGou
 *
 */
public class FileUtil {

	public static boolean writeToFile(String path, String fileName, String content) {
		boolean result = false;
		try {
			File p = new File(path);
			p.mkdirs();
			File file = new File(path + fileName);
			file.createNewFile();
			BufferedWriter output = new BufferedWriter(new FileWriter(file));
			output.write(content);
			output.close();
			result = true;
		} catch (Exception ex) {
			ex.printStackTrace();
		}		
		return result;
	}	

	public static String readFileContent(File fileName) {
		StringBuffer sb = new StringBuffer();
		try {
			FileReader read = new FileReader(fileName);
			char ch[] = new char[1024];
			int d = read.read(ch);
			while (d != -1) {
				String str = new String(ch, 0, d);
				sb.append(str);
				d = read.read(ch);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		}
		return sb.toString();
	}	
}
